<script lang="ts" setup>
import { onMounted } from 'vue'
import type { Employee } from '../../types/employee'
import { getEmployee } from '../../functions/core'
import Upload from '@/module/informationManagement/components/employee/Upload.vue'
// import { QAIndexDB } from '@/utils/indexDB'

// import { useRouter } from 'vue-router'

// const router = useRouter()

const openValue = ref(false)
const employeeData = ref<Employee[]>([])
const columns = [
  {
    key: 'name',
    dataIndex: 'name',
    title: '姓名',
  },
  {
    key: 'customerName',
    dataIndex: 'customerName',
    title: '客户名称',
  },
  {
    key: 'projectName',
    dataIndex: 'projectName',
    title: '项目中文名',
  },
  {
    key: 'projectCode',
    dataIndex: 'projectCode',
    title: '项目编码',
  },
  {
    key: 'customerLevel',
    dataIndex: 'customerLevel',
    title: '报客户级别',
  },
  {
    key: 'projectApprovalCode',
    dataIndex: 'projectApprovalCode',
    title: '立项编码',
  },

]

function onConfirm(data: Employee[]) {
  openValue.value = false
  employeeData.value = data
}

// async function getEmployee() {
//   const res = await QAIndexDB.getItem<Employee[]>('EMPLOYEE')
//   if (res) {
//     employeeData.value = res
//   }
// }
onMounted(() => {
  getEmployee().then((res) => {
    if (res) {
      employeeData.value = res
    }
  })
})
</script>

<template>
  <div class="space-y-5">
    <div class="flex">
      <a-button type="primary" @click="openValue = true">
        上传员工信息
      </a-button>
    </div>
    <Upload v-model:open="openValue" @confirm="onConfirm" />
    <a-table :columns="columns" :data-source="employeeData" />
  </div>
</template>

<style lang="scss" scoped>
.ant-tabs {
  margin-top: 16px;
}
</style>
